// Learn cc.Class:
//  - https://docs.cocos.com/creator/manual/en/scripting/class.html
// Learn Attribute:
//  - https://docs.cocos.com/creator/manual/en/scripting/reference/attributes.html
// Learn life-cycle callbacks:
//  - https://docs.cocos.com/creator/manual/en/scripting/life-cycle-callbacks.html

var Config = require('Config')
var CreatorHelper = require('CreatorHelper')
var ClickManager = require('ClickManager')

cc.Class({
    extends: cc.Component,

    properties: {
        // foo: {
        //     // ATTRIBUTES:
        //     default: null,        // The default value will be used only when the component attaching
        //                           // to a node for the first time
        //     type: cc.SpriteFrame, // optional, default is typeof default
        //     serializable: true,   // optional, default is true
        // },
        // bar: {
        //     get () {
        //         return this._bar;
        //     },
        //     set (value) {
        //         this._bar = value;
        //     }
        // },
        gameContent: [
            cc.Node,
            cc.Node,
            cc.Node,
            cc.Node
        ],
        gameTitle: [
            cc.Sprite,
            cc.Sprite,
            cc.Sprite,
            cc.Sprite
        ],
        gameTitleNode: [
            cc.Node,
            cc.Node,
            cc.Node,
            cc.Node
        ]
    },

    // LIFE-CYCLE CALLBACKS:

    onLoad () {
        for (let i = 0; i < 4; i++) {
            ClickManager.onClick (this.gameTitleNode[i], this, (arg) => {
                this.handleChangeEv(i)
            })
        }
    },

    start () {
    },

    handleChangeEv (index) {
        let selectPath = 'images/smallimages/model/game_info/select'
        let selectedPath = 'images/smallimages/model/game_info/selected'

        for (let i = 0; i < 4; i++) {
            CreatorHelper.changeSpriteFrame(this.gameTitle[i], selectPath)
            this.gameContent[i].active = false
        }

        this.gameContent[index].active = true
        CreatorHelper.changeSpriteFrame(this.gameTitle[index], selectedPath)
    }

    // update (dt) {},
});
